﻿using Hr.DAL;
using Hr.DALContainer;
using Hr.IBLL;
using Hr.IDAL;
using Hr.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hr.BLL
{
    public partial class CarService : BaseService<Car_List>, ICar_ListService
    {
        private ICar_ListDAL ICar_ListDAL = Container.Resolve<ICar_ListDAL>();
        //引入 自己的Dal层
        protected CarDAL CL1 = new CarDAL();

        /// <summary>
        /// 获取接受人信息,带模糊查询
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetUserList(int page,int limit,string SelName)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
          {
            {"CarList",CL1.GetUserList(SelName).Skip(limit*(page-1)).Take(limit) },
            {"CarCount",CL1.GetUserList(SelName).Count() }

          };
            return dt;
        }

        /// <summary>
        /// 车辆信息获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        ///
        public IEnumerable<object> GetCarSet(string Title)
        {
            return CL1.GetCarSet(Title);
        }

        /// <summary>
        /// 添加车辆信息
        /// </summary>
        /// <param name="Car"></param>
        /// <param name="CarSet"></param>
        /// <param name="ViewCar"></param>
        /// <param name="UserList"></param>
        /// <returns></returns>
        public bool AddCar(Car_List Car,string Type,int pk_User)
        {
            try
            {
                //表的先后调用添加
                CL1.AddCarListInfo(Car, Type,pk_User);
                return CL1.SaveChanges();
            }
            catch (Exception)
            {
                //写日志
                return false;
            }
        }

        /// <summary>
        /// 获取用车类型 和 车辆列表信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string,object> GetCarListType()
        { 
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
               {"Set",CL1.GetCarListType()},
               {"Type",CL1.GetMyModels<Sys_TypeID>(n=>n.TableName.Equals("Car_List"))}
            };
            return dt;
        }
      
        /// <summary>
        /// 根据ID 获取用车管理数据
        /// </summary>
        public Car_List GetCarListInfo(int id)
        {
            return CL1.GetCarList(id);
        }

        /// <summary>
        /// 根据ID获取审核数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public object GetCheckInfo(int id)
        {
            return CL1.GetCheckInfo(id);
        }

        /// <summary>
        /// 根据ID获取车辆管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Car_Set GetSetinfo(int id)
        {
            return CL1.GetSetinfo(id);
        }

        /// <summary>
        /// 获取车辆管理信息
        /// </summary>
        /// <returns></returns>
        public IEnumerable<object> GetCarSetList(string SelName)
        {
            return CL1.GetCarSetList(SelName);
        }

        /// <summary>
        /// 获取审核管理信息
        /// </summary>
        /// <returns></returns>
        //public IEnumerable<object> GetCheckList(string Title)
        //{

        //    return CL1.GetCheckList(Title);
        //}
        public Dictionary<string, object> GetCheckList(int page, int limit, string Title)
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
            {
                {"CarList",CL1.GetCheckList(Title).Skip(limit*(page-1)).Take(limit) },
                {"Count",CL1.GetCheckList(Title).Count() }
            };
            return dt;
        }

        /// <summary>
        /// 添加，修改车辆管理
        /// </summary>
        /// <param name="s"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool UpdateSet(Car_Set s ,string type)
        {
            CL1.GetSet(s, type);
            return CL1.Savechanges();
        }

        /// <summary>
        /// 获取车辆管理类型
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetTypeList()
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
           {
               {"Type",CL1.GetMyModels<Sys_TypeID>(n=>n.TableName.Equals("Car_Set"))},
               {"Set",CL1.GetMyModels<Sys_StatusID>(n=>n.TableName.Equals("Car_Set"))},
           };
            return dt;
        }

        /// <summary>
        /// 获取用车管理类型
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetTypeInfo()
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
           {
               {"Type",CL1.GetMyModels<Sys_TypeID>(n=>n.TableName.Equals("Car_set"))},
               {"Status",CL1.GetMyModels<Sys_StatusID>(n=>n.TableName.Equals("Car_set"))}
           };
            return dt;
        }

        /// <summary>
        /// 获取所有下拉框
        /// </summary>
        /// <returns></returns>
        public Dictionary<string,object> GetCheckType()
        {
            Dictionary<string, object> dt = new Dictionary<string, object>()
           {
               {"Type",CL1.GetMyModels<Sys_TypeID>(n=>n.TableName.Equals("Car_List"))},
               {"Set",CL1.GetCarListType()},
               {"Status",CL1.GetMyModels<Sys_StatusID>(n=>n.TableName.Equals("Car_List"))}
           };
            return dt;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="c"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public bool Update(Car_List c,int User)
        {
            CL1.Update(c, User);
            return CL1.Savechanges();
        }

        /// <summary>
        /// 删除审核信息
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool DeleteCheck(Car_List l)
        {
            CL1.DeteleCheck(l);
            return CL1.Savechanges();
        }

        /// <summary>
        ///删除车辆
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public bool DeleteCarSet(Car_Set s)
        {
            CL1.DeteleCarSet(s);
            return CL1.Savechanges(); 
        }

        /// <summary>
        /// 删除用车管理
        /// </summary>
        /// <param name="cl"></param>
        /// <returns></returns>
        public bool DeleteCarInfo(Car_List cl)
        {
            CL1.DeteleCarInfo(cl);
            return CL1.Savechanges();
        }


        /// <summary>
        /// pk_Car删除车辆审核记录
        /// </summary>
        /// <param name="s"></param>

        

        public bool DelCarListData(int pk_Car)
        {
            CL1.DelCarListData(pk_Car);

            return CL1.Savechanges();
        }


        public override void SetDal()
        {
            Dal = ICar_ListDAL;
        }
    }
}
